/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================break 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    manualBreaks:[],//break列表,
    breakList:[],
    breakEmployeeList:[],

  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    /**
     *查询手动break 列表
     * @param commit
     * @param paramData = {employeeId:1231}
     * @returns {Promise}
     */
    getManualBreaks({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/break/getManualTakeBreakList',
          data:paramData,
          type:'get',
          success:function (data) {
            console.log(data)
            commit('setCommonStateData',{key:'manualBreaks',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     *
     * @param commit
     * @param paramData ={id:123,isActived:true}
     * @returns {Promise}
     */
    activeBreak({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/break/activeBreak',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    getManualBreakEmployeeList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/break/getManualTakeBreakList',
          data:paramData,
          type:'get',
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    getBreakEmployeeList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/breakEmployee/getBreakEmployees',
          data:paramData,
          type:'get',
          success:function (data) {
            commit('setCommonStateData',{key:'breakEmployeeList',data:data.data});
            resolve(data);
          }
        })
      })
    },
    saveBreak({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url: '/time/break/saveBreak',
          data: JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success: function (data) {
            resolve(data);
          }
        })
      })
    },
    deleteBreak({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url: '/time/break/delBreaks',
          data: paramData,
          success: function (data) {
            resolve(data);
          }
        })
      })
    },
    getBreakList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url: '/time/break/getBreakList',
          data: paramData,
          type:'get',
          success: function (data) {
            commit('setCommonStateData',{key:'breakList',data:data.data});
            resolve(data);
          }
        })
      })
    },
    modifyBreakEmployees({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url: '/time/breakEmployee/modifyBreakEmployees',
          data: JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success: function (data) {
            resolve(data);
          }
        })
      })
    },
    setIsAllEmployee({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url: '/time/break/setIsAllEmployee',
          data: paramData,
          success: function (data) {
            resolve(data);
          }
        })
      })
    },
  },
  getters: {
    //打卡数据
    manualBreaks:(state, getters)=> {
      return state.manualBreaks;
    },
    breakList:(state, getters)=> {
      return state.breakList;
    },
    breakEmployeeList:(state, getters)=> {
      return state.breakEmployeeList;
    },
  }
}
